﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Models
{
    public class MemberIProvider : IProvider<Members>
    {   
        private SMEntities db=new SMEntities();
        public int Delete(int Id)
        {
           Members entity=  db.Members.Find(Id);
            if(entity != null)
            {
                db.Members.Remove(entity);
               int  A=   db.SaveChanges();
                return A;
            }
            return 0;
        }

        public List<Members> GetAll()
        {
            return db.Members.ToList();
        }

        public int Insert(Members t)
        {
              db.Members.Add(t);
           int affectedRows = db.SaveChanges();
            return affectedRows;
        }

        public int Update(Members t)
        {
           Members entity = db.Members.FirstOrDefault(e => e.Id == t.Id);
            if(entity != null)
            {
                 // 修改实体属性值
            entity.Name = t.Name;
            entity.Password = t.Password;
            return          db.SaveChanges();
            }
            return 0;
        }
          public Members GetById(int Id)
        {
            Members entity=  db.Members.Find(Id);
            return entity;
        }
    }
}
